package com.huangfu.learning.javabase.java.reflect;

import java.lang.reflect.Method;

/**
 * Created with IntelliJ IDEA.
 * Author: huangfu.daohui
 * Date: 2018/7/10
 * Time: 20:07
 * Version: 1.0
 * Description:
 **/
public class SimpleDemo {

    public void test() {
        System.out.println("测试方法");
    }

    public static void main(String[] args) {
        SimpleDemo simpleDemo = new SimpleDemo();
        Class<?> clazz = null;
        Class<?> clazz2 = null;
        try {
            //下面两种方式都可以获得类，官方推荐第二种
            clazz2 = simpleDemo.getClass();
            //更推荐这种方式获取类名
            clazz=Class.forName("com.huangfu.learning.javabase.java.reflect.SimpleDemo");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        System.out.println("获取类名：" + clazz.getName());
        System.out.println("获取方法名：" + clazz.getMethods()[0]);
        System.out.println("获取自定义方法名：" + clazz.getDeclaredMethods());

        for (Method method : clazz.getMethods()) {
            System.out.println("方法名(包含父类的):" + method);
        }
        System.out.println("======================================");
        for (Method method : clazz.getDeclaredMethods()) {
            System.out.println("方法名(不包含父类的):" + method);
        }

    }
}
